﻿using System;

namespace Mg.Components
{
    /// <summary>
    /// 定义容器注册接口
    /// </summary>
    public interface IObjectContainer
    {
        /// <summary>
        /// 根据类型注册对象
        /// </summary>
        /// <param name="implementationType">注册类型</param>
        /// <param name="life">生命周期</param>
        void RegisterType(Type implementationType, LifeStyle life = LifeStyle.Singleton);
        /// <summary>
        /// 更具目标类型注册目标的实现类型
        /// </summary>
        /// <param name="serviceType">目标类型</param>
        /// <param name="implementationType">目标实现类型</param>
        /// <param name="life">生命周期</param>
        void RegisterType(Type serviceType, Type implementationType, LifeStyle life = LifeStyle.Singleton);
        /// <summary>
        /// 注册目标类型的目标实现类型，并且设置生命周期
        /// </summary>
        /// <typeparam name="TService">目标类型</typeparam>
        /// <typeparam name="TImplementer">目标实现类型</typeparam>
        /// <param name="life">生命周期</param>
        void Register<TService, TImplementer>(LifeStyle life = LifeStyle.Singleton)
            where TService : class
            where TImplementer : class, TService;
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TService">The service type.</typeparam>
        /// <typeparam name="TImplementer">The implementer type.</typeparam>
        /// <param name="instance">The implementer type instance.</param>
        void RegisterInstance<TService, TImplementer>(TImplementer instance)
            where TService : class
            where TImplementer : class, TService;
        /// <summary>
        /// 根据类型返回注册的对象
        /// </summary>
        /// <typeparam name="TService">对象类型</typeparam>
        /// <returns></returns>
        TService Resolve<TService>() where TService : class;
        /// <summary>
        /// 根据类型返回注册的对象
        /// </summary>
        /// <param name="serviceType">对象类型</param>
        /// <returns></returns>
        object Resolve(Type serviceType);
    }
}
